﻿{$header}
<div id="main" class="main" >
    <div class="content">
  <h3 class="heading">编辑采购询价单 [ <a href="__URL__">返回列表</a> ]
    <!--只能销售有权限，采购无权动下面三个按钮-->
    <div class="btn-group pull-right">
  
  <form id="offer3"  method="post"  action="__APP__/Inquiry/update" class="form-inline" >
        <input type="hidden" name='id' value='{$vo.inquiry_id}'>
        <input type="hidden" name="status" value="9">

        <input type="hidden" name="jumpUrl"  value="__APP__/Inquiry/index/charge_man/{:$_SESSION[C('USER_AUTH_KEY')]}/ask_status/8">
  <a class="btn btn-primary" onclick="javascript:changeInquiryStatus(3)"><i class="icon-shopping-cart icon-white"></i> 还价处理完成</a>
</form>

</div>
  </h3>
<div id="result" class="result none"></div>
<form id="offer2"  method="post" action="__APP__/Inquiry/update" class="form-inline" >
        <input type="hidden" name="id" value='{$vo.inquiry_id}'>
        <input type="hidden" name="status" value="6">
        <input type="hidden" name="ask_supplier_id" value="{$vo.id}">

        <input type="hidden" name="jumpUrl"  value="__APP__/Inquiry/index/charge_man/{:$_SESSION[C('USER_AUTH_KEY')]}/ask_status/5">
        <textarea name="ask_remark" class="span8" rows=3>{$vo.remark}</textarea>
  <a class="btn btn-primary" onclick="javascript:changeInquiryStatus(2)"><i class="icon-question-sign icon-white"></i> 客户还价-待更新</a>
</form>

<form class="form-horizontal well" method='post' id="form1" action="__URL__/update/">
<table>
<tr>
    <td>询价单编号：</td>
    <td>{$vo.mano} <span class="offset1">客户询单号：</span>
      {$vo.inquiry_id|getModelName='Inquiry','mano'}  
      <input type="hidden" name="inquiry_id" value="{$vo.inquiry_id}">
    </td>
</tr>

<tr>
	<td>产品</td>
	<td>{$vo.product_id|getPfullName}
 CAS: {$vo.product_id|getModelName='Product','cas'} <a href="__APP__/Product/edit/id/{$vo.product_id}" class="offset1" target="_blank">查看产品</a> 
    <img src="__PUBLIC__/Uploads/product/{$vo.product_id|getCas}.jpg">
  </td> </tr>
<tr>
    <td>数量：</td>
    <td><input type="text" name="number" value="{$vo.number}" class="input-xxlarge">
      要求要求交货期 <input type="text" class="span2" name="delivery_date" value="{$vo.delivery_date|toDate="Y-m-d"}" onClick="WdatePicker({dateFmt:'yyyy-MM-dd'})">
    </td>
</tr>
<tr>
    <td>询单要求：</td>
    <td>
      <textarea class="span12" name="specification" rows="3">{$vo.specification}</textarea>
</tr>
<tr>
    <td>优先级</td><td>{:configList( C('priority'),$vo['priority'],'priority' )}</td>
</tr>
<tr>
    <td>负责人</td><td>{$vo.charge_man|getModelName='User'}</td>
</tr>
<tr>
    <td class="tRight">询价状态</td>
    <td class="tLeft"> {$vo.status|getConfigVal='askStatus'} 经办人：{:modList('User')}  询价时间：{$vo.create_time|toDate}
        </td>
</tr>
<tr>
  <td>询价状态操作</td>
  <td>
      <if condition="($vo['status'] lt 5 ) or empty($vo['inquiry_id'])">
        <select name='status'>
          <option value="1">采购询价中</option>
          <option value="2">初步结果</option>
          <option value="3">等待最终确认</option>
          <option value="4">询价完成，待报价</option>
        </select>

      </if>
      <if condition="($vo['status'] gt 5 )  and ($vo['status'] lt 9 ) ">
        <select name='status'>
          <option value="7">采购更新中</option>
          <option value="8">采购更新完成</option>
        </select>
      </if>
  </td>
</tr>
<tr>
  <td colspan=2>&nbsp;</td>
  
</tr>

<if condition="($vo['status'] eq 5 ) or ($vo['status'] eq 9 )">
  <else/>
<tr>
	<td></td>
	<td class="center" width="300">
        <input type="hidden" value="__SELF__" name="jumpUrl">
        <input type="hidden" value="{$vo.id}" name="id">
	<button type="submit" class="btn btn-primary"><i class="icon-ok icon-white"></i> 保存</button>
	<button type="reset" onclick="javascript:history.back()" class="btn btn-primary offset1"><i class="icon-arrow-left icon-white"></i> 返回</button>
	</td>
</tr>
</if>

</table>
</form>
<p class="heading">供应商报价 : &nbsp;{$vo.product_id|getPfullName}
 CAS: {$vo.product_id|getModelName='Product','cas'} 
  <button class="btn btn-primary" onclick="addMore({$vo.id})"/><i class="icon-plus icon-white"></i> 新增报价</button> </p>

<table class="table table-bordered table-striped">
      <tr>
        <th>供应商</th><th>联系人</th><th>合作记录</th><th>报价 格式：
        <span class="info">纯度 99.5％ ；液体；6.1类危险品 ；性质稳定 ； <br/> 100g：3000/100g， 1周；1kg：8000/ kg 30天; 开票价，不开票-10% ，或者不开票价重新列举</span>
        </th> <th>创建时间</th><th>更新时间</th><th>询价结果自评</th><th>业务报价</th><th>备注</th> <th>修改</th>
      </tr>
      <volist name="offers" id="off">
        <form action="__APP__/Ask_supplier_detail/update" method="post">
        <tr>
          <td class="span1">
            <input type="hidden" name='update_time' value={:time()}>
            <input type="hidden" name="id" value="{$off.id}">
            <input type="hidden" value="__URL__/edit/id/{$vo.id}" name="jumpUrl">
            <div style="width:120px;word-wrap:break-word;"> <a href="__APP__/Supplier/edit/id/{$off.supplier_id}" target="_blank">{$off.supplier_id|getSupplierAndRank}</a> </div></td>
            <php>$contact = M('Contact')->where('supplier_id ='.$off['supplier_id'])->findAll(); </php>
          <td>
            <select name="contact_id" id="" class="span2">
               <volist name="contact" id="ca">
                 <option value="{$ca.id}" <eq name="off.contact_id" value="$ca.id">selected</eq> >{$ca.name}--{$ca.id|getContactInfo}</option>
               </volist>

            </select>
          </td>
          <?php $count_buys = M('Buy')->where('supplier_id = '.$off['supplier_id']) ->count(); ?>
          <td><a href="__APP__/Supplier/edit/id/{$off.supplier_id}#buy" target="_blank">合作记录({$count_buys})</a> </td>
          <td>
             <textarea name="offer" class="input-xxlarge" rows="3" >{$off.offer}</textarea>
          </td>
          <td>{$off.create_time|toDate}</td>
          <td>{$off.update_time|toDate}</td>
          <td>{:configList(C('askrank'),$off['status'])}</td>
          <td>{:configList(C('sale_consult'),$off['sale_consult'],'sale_consult','input-mini')}
            <if condition="($vo['status'] eq 5 ) or ($vo['status'] eq 9 )">
          <else/>
                <a class="btn btn-primary" href="javascript:void(0)" onclick="inquiry_offer({$vo.inquiry_id},{$off.id})"> 报价</a>
            </if> 
          </td>
          <td><textarea name="specification" class="input-medium"  rows="3" >{$off.specification}</textarea> </td>
          <td> 
            <if condition="($vo['status'] eq 5 ) or ($vo['status'] eq 9 )">
          <else/>
                <button type="sumbit" class="btn btn-primary">修改</button> 
            </if>
          </td>
        </tr>
        </form>
      </volist>

    </table>

<ul id="myTab" class="nav nav-tabs">
    <li class="active"><a href="#ask_history" data-toggle="tab">历史询价</a></li>
    <li><a href="#buy_history" data-toggle="tab">采购记录({$products|count})</a></li>
    <li><a href="#potential_supplier" data-toggle="tab">潜在供应商({$suppliers|count})</a></li>
    <li><a href="javascript:void(0)" class="btn" onclick="searchSupplier({$vo.id})"><i class="icon-search icon-white"></i> 高级（订制）</a></li>
</ul>
<div id="myTabContent" class="tab-content">
  <div class="tab-pane fade in active" id="ask_history">
    <table class="table table-bordered table-striped">
    <tr><td colspan=10 class="alert alert-info"><i class="icon-arrow-down"></i> 历史询价</td> </tr>
    <tr> <th>供应商</th><th>联系人</th><th>合作记录</th><th>报价</th><th>询价时间</th><th>更新时间</th><th>询价结果自评</th><th>业务报价</th> <th>备注</th><th>复制报价</th> </tr>
      <volist name="his_offers" id="hoff">
        <tr>
          <td><a href="__APP__/Supplier/edit/id/{$hoff.supplier_id}" target="_blank">{$hoff.supplier_id|getModelName="Supplier"}</a> </td>
          <td>{$hoff.contact_id|getContactInfo}</td>
          <td><a href="__APP__/Supplier/edit/id/{$off.supplier_id}#buy" target="_blank">合作记录</a> </td>
          <td>{$hoff.offer} </td>
          <td>{$hoff.create_time|toDate}</td>
          <td>{$hoff.update_time|toDate}</td>
          <td>{$hoff.status|getConfigVal='askrank'}</td>
          <td>{$hoff.sale_consult|getConfigVal='sale_consult'}</td>
          <td>{$hoff.specification}</td>
          <td> 
            <button class="btn btn-primary" onclick="copyMore({$vo.id},{$hoff.supplier_id})"/><i class="icon-plus icon-white"></i> 复制报价</button>
          </td>
        </tr>
      </volist>
      {$page0}
    </table>

  </div>

  <div class="tab-pane" id="buy_history">
    <table class="table">
      <tr><th>编号</th><th>采购单号</th> <th>规格</th><th>数量</th><th>供应商</th><th>单价</th><th>创建时间</th><th>状态</th><th>异常管理状态</th><th>操作</th> </tr>
      <volist name="products" id="ca">
        <tr>
        <td>{$ca.id}</td>
        <td>{$ca.mano}</td>
        <td>{$ca.specification|getModelName='Specification'}</td>
        <td>{$ca.number}</td>
        <td>{$ca.supplier_id|getModelName='Supplier'}</td>
        <td>{$ca.price}</td>
        <td>{$ca.create_time|toDate}</td>
        <td>{$ca.status|getConfigVal='buystatus'}</td>
        <td>{$ca.exception_status|getConfigVal='exceptionstatus'}</td>
        <td><button class="btn btn-primary" onclick="copyMore({$vo.id},{$ca.supplier_id})"/><i class="icon-plus icon-white"></i> 复制报价</button></td>
      </tr>
      </volist>
      {$page}
    </table>

  </div>

  <div class="tab-pane" id="potential_supplier">
    <table class="table">
      <tr><th>编号</th><th>供应商</th><th>操作</th>  </tr>
      <volist name="suppliers" id="sp">
        <tr>
        <td>{$sp.id}</td>
        <td>{$sp.supplier_id|getModelName="Supplier"}</td>
        <td><button class="btn btn-primary" onclick="copyMore({$vo.id},{$sp.supplier_id})"/><i class="icon-plus icon-white"></i> 复制报价</button></td>
      </tr>
      </volist>
      {$page2}
    </table>

  </div>

</div><!--end tab-->

</div>
</div>
<include file="Public:footer" />
<load href="__PUBLIC__/Js/jquery-1.7.2.min.js"/>
<load href="__PUBLIC__/bootstrap/js/bootstrap-tab.js" />
<load href="__PUBLIC__/Js/My97DatePicker/WdatePicker.js" />
<script type="text/javascript">
   function addMore(id){
       location.href ="__APP__/Ask_supplier_detail/add/asid/"+id;

        }
   function copyMore(id,hid){
       location.href ="__APP__/Ask_supplier_detail/add/asid/"+id+"/offerid/"+hid;

        }
  function searchSupplier(id){
    if(id)
       window.open(APP+'/Supplier/view_search?form=form1&asid='+id,'selected','directorys=no,toolbar=no,status=no,menubar=no,resizable=yes,width=1000,height=800,top=100,left=120,scrollbars=yes');
    else
      alert("请选择供应商");
      return false;
  }

  function changeInquiryStatus(id){
        if (window.confirm('确定要处理客户询单吗？'))
        {
          $('#offer'+id).submit();
        }
    }
  function inquiry_offer(inquiry_id,ask_supplier_detail_id){
        if (window.confirm('确定要报价吗？'))
        {
            location.href="__APP__/Inquiry/inquiry_offer/inquiry_id/"+inquiry_id+"/ask_supplier_detail_id/"+ask_supplier_detail_id;
        }else
            return false;

    }
</script>
